﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;

namespace Mailer.Utilities
{
	public class MailUtilities
	{

		static bool BaseQueueMessage(MailAddress receipient, string subject, string fullbody, bool ishtml)
		{
			MailMessage mm = new MailMessage();
			mm.From = new MailAddress(Configuration.SystemEmail, Configuration.SystemName);
			mm.To.Add(receipient);
			mm.Body = fullbody;
			mm.Subject = subject;
			mm.IsBodyHtml = ishtml;

			bool ret = false;

			Logger.Info(typeof(MailUtilities), "Sending mail to: " + receipient.Address + " <" + receipient.DisplayName + ">, subject: " + subject + ", body:\n" + fullbody);


			try
			{
				SmtpClient sc = new SmtpClient();
				sc.Send(mm);
				ret = true;
			}
			catch (Exception z)
			{
				Logger.Warn(typeof(MailUtilities), z.ToString());
			}

			return ret;
		}

		public static bool QueueInfoMessage(MailAddress receipient, string subject, string body)
		{
			return BaseQueueMessage(receipient, subject, body, false);
		}

		public static bool QueueStatusMessage(MailAddress receipient, string subject, string body)
		{
			return BaseQueueMessage(receipient, subject, body, false);
		}

		public static bool QueueDebugMessage(MailAddress receipient, string subject, string body)
		{
			return BaseQueueMessage(receipient, "[" + Configuration.SystemName + " debug] " + subject, body, false);
		}

		public static bool QueueAdminMessage(MailAddress receipient, string subject, string body)
		{

			return BaseQueueMessage(receipient, "[" + Configuration.SystemName + " admin] " + subject, body, false);
		}


		 



	}
}
